package ro.ubbcluj.cs.damate.managers.resources;

import org.primefaces.model.TreeNode;

import java.util.Comparator;

/**
 * @author Lóránd Fazakas (lfazakas)
 *         Date: 2013.06.30.
 *         Time: 23:15
 */
public class ResourceComparator implements Comparator<TreeNode> {

    @Override
    public int compare(TreeNode node1, TreeNode node2) {
        if (node1.getData().toString().equalsIgnoreCase("src")) {
           return -10;
        } else if (node2.getData().toString().equalsIgnoreCase("src")) {
           return 10;
        } else if (!node1.isLeaf() && node2.isLeaf()) {
            return -5;
        } else if (node1.isLeaf() && !node2.isLeaf()) {
            return 5;
        } else if (node1.getData().toString().startsWith(".") && node2.getData().toString().startsWith(".")) {
            return node1.getData().toString().compareTo(node2.getData().toString());
        } else if (node1.getData().toString().startsWith(".")) {
            return -1;
        } else if (node2.getData().toString().startsWith(".")) {
            return 1;
        } else {
            return node1.getData().toString().compareTo(node2.getData().toString());
        }
    }
}
